package com.imau;

import com.imau.bean.User;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {


        try {
            //1. 获取连接
            String url = "jdbc:mysql://127.0.0.1:3306/db1";
            String username = "root";
            String password = "1234";
            Connection conn = DriverManager.getConnection(url, username, password);

            //2. 定义sql
            String sql = "select * from tb_user wehre userName=? and password=?";

            //3. 获取执行sql的对象
            PreparedStatement pstmt = conn.prepareStatement(sql);

            //4. 设置参数
            pstmt.setString(1, "zhangsan");
            pstmt.setString(2, "123456");

            //5. 执行sql
            ResultSet resultSet = pstmt.executeQuery();

            //6. 封装结果
            User user = null;
            List<User> users = new ArrayList<User>();

            while (resultSet.next())
            {
                String userName = resultSet.getString("username");
                String userpassword = resultSet.getString("password");
                user = new User(userName,userpassword);

                users.add(user);
            }
        }catch (Exception e)
        {
            e.printStackTrace();
        }


    }
}